//
//  ZCVisiterView.swift
//  weibo
//
//  Created by 张城 on 16/7/19.
//  Copyright © 2016年 张城. All rights reserved.
//

import UIKit

class ZCVisiterView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor(red: 237/255, green: 237/255, blue: 237/255, alpha: 1)
        setupUI()
//        setupAnim()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupVisiterView(title: String?,imgName: String?) {
        if let til = title,let img = imgName  {
            messageLabel.text = til
            houseImg.image = UIImage(named: img)
            loopImg.hidden = true
        } else {
            setupAnim()
        }
    }
    
    func setupAnim() {
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue = M_PI * 2
        anim.repeatCount = MAXFLOAT
        anim.duration = 10
        anim.removedOnCompletion = false
        loopImg.layer.addAnimation(anim, forKey: nil)
    }
    
    
    func setupUI() {
        addSubview(loopImg)
        addSubview(maskImg)
        addSubview(houseImg)
        addSubview(messageLabel)
        addSubview(loginBut)
        addSubview(registerBut)
        
        loopImg.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        
        maskImg.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        
        houseImg.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        
        messageLabel.snp_makeConstraints { (make) in
            make.size.equalTo(CGSizeMake(230, 36))
            make.top.equalTo(maskImg.snp_bottom).offset(16)
            make.centerX.equalTo(self)
        }
        
        loginBut.snp_makeConstraints { (make) in
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
            make.size.equalTo(CGSizeMake(100, 36))
            make.left.equalTo(messageLabel)
        }
        
        registerBut.snp_makeConstraints { (make) in
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
            make.size.equalTo(CGSizeMake(100, 36))
            make.right.equalTo(messageLabel)
        }
    }
    
    lazy var loopImg: UIImageView = {
       let imgV = UIImageView()
        imgV.image = UIImage(named: "visitordiscover_feed_image_smallicon")
        imgV.sizeToFit()
        return imgV
    }()
    
    lazy var maskImg: UIImageView = {
        let imgV = UIImageView()
        imgV.image = UIImage(named: "visitordiscover_feed_mask_smallicon")
        imgV.sizeToFit()
        return imgV
    }()
    
    lazy var houseImg: UIImageView = {
        let imgV = UIImageView()
        imgV.image = UIImage(named: "visitordiscover_feed_image_house")
        imgV.sizeToFit()
        return imgV
    }()
    
    lazy var messageLabel: UILabel = {
       let label = UILabel()
        label.font = UIFont.systemFontOfSize(14)
        label.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        label.textAlignment = .Center
        label.textColor = UIColor.grayColor()
        label.numberOfLines = 0
        return label
    }()
    
    lazy var loginBut: UIButton = {
       let but = UIButton()
        but.setTitle("登 录", forState: .Normal)
        but.titleLabel?.font = UIFont.systemFontOfSize(14)
        but.setTitleColor(UIColor.orangeColor(), forState: .Normal)
        but.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: .Normal)
        but.addTarget(self, action: #selector(ZCVisiterView.loginButtonClick), forControlEvents: .TouchUpInside)
        return but
    }()
    
    lazy var registerBut: UIButton = {
        let but = UIButton()
        but.setTitle("注 册", forState: .Normal)
        but.titleLabel?.font = UIFont.systemFontOfSize(14)
        but.setTitleColor(UIColor.orangeColor(), forState: .Normal)
        but.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: .Normal)
        but.addTarget(self, action: #selector(ZCVisiterView.loginButtonClick), forControlEvents: .TouchUpInside)
        return but
    }()
    
    var callback:(()->())?
    
    func loginButtonClick()  {
        callback?()
    }
    
}
